<script setup lang="ts">

import type { CodeItem } from '@/type/common/list-types'
import { computed } from 'vue'

const props = defineProps<{ codes: CodeItem[], codeType: string, codeKey: string }>()

// 使用 computed 确保 code 基于最新的 codes 和 codeKey 计算得出
const code = computed(() => {
  return props.codes.find(item => item.itemId == props.codeKey)
})


</script>

<template>

  <span v-if="code === undefined" v-text="codeKey"/>
  <span v-else-if="codeType === 'text'" v-text="code.itemName"/>
  <component v-else-if="codeType === 'tag'" :is="'el-tag'" :type="code.tagType === undefined ? 'info' : code.tagType">
    {{ code.itemName }}
  </component>

</template>

<style scoped>

</style>